package routes

import (
	"gitee.com/goblog2/http/controllers"
	"gitee.com/goblog2/http/middleware"
	"github.com/gorilla/mux"
	"net/http"
)

func RegisterRoutes(router *mux.Router) {

	pc := controllers.PageController{}
	router.HandleFunc("/", pc.Home).Name("home")
	router.HandleFunc("/about", pc.About).Name("about")
	router.NotFoundHandler = http.HandlerFunc(pc.NotFound)

	ac := controllers.ArticleController{Controller: &controllers.BaseController}
	router.HandleFunc("/articles", ac.Index).Methods("get").Name("articles.index")
	router.HandleFunc("/articles/create", ac.Create).Methods("get").Name("articles.create")
	router.HandleFunc("/articles", ac.Store).Methods("post").Name("articles.store")
	router.HandleFunc("/articles/{id:[0-9]+}", ac.Show).Methods("get").Name("articles.show")
	router.HandleFunc("/articles/{id:[0-9]+}/edit", ac.Edit).Methods("get").Name("articles.edit")
	router.HandleFunc("/articles/{id:[0-9]+}", ac.Update).Methods("put").Name("articles.update")
	router.HandleFunc("/articles/{id:[0-9]+}", ac.Destroy).Methods("delete").Name("articles.destroy")

	router.Use(middleware.ContentTypeMiddleware)
}
